const express = require('express')
const router = express.Router()

router.get('/test', function (req, res, next) {
    setTimeout(() => {
        res.send({ status: true, msg: '测试成功' })
    }, 5000)
})

const jwt = require('../../util/jwt')
const jwtConfig = require('../../config/jwt')

async function checkToken(req, res, next) {
    if (req.headers.softeem_token) {
        let user_info = await jwt.verify(req.headers.softeem_token, jwtConfig.PrivateKey)
        req.user_info = user_info
        next()
    } else {
        next({ status: 'fail', msg: '缺少token' })
    }
}

router.use('/user', require('./user'))
router.use('/category', require('./category'))
router.use('/food', require('./food'))
router.use('/comment', require('./comment'))
router.use('/order', checkToken, require('./order'))
router.use('/address', checkToken, require('./address'))
router.use('/shopCart', checkToken, require('./shopCart'))
// 此路由为管理员才可操作
router.use('/banner', require('./banner'))

module.exports = router

